package o;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class cmq {
    private static final String ॱ = (epp.ˊ(ContentManager.getInstant().getContext()) + "Diagnose.log");
    private Executor ʼ = Executors.newCachedThreadPool();
    private int ˊ = 0;
    private final StringBuffer ˋ = new StringBuffer();
    private int ˎ = 0;
    private Context ˏ;
    private Handler ॱॱ;

    public cmq(Context context, Handler handler) {
        ˋॱ();
        this.ॱॱ = handler;
        this.ˏ = context.getApplicationContext();
        ॱˊ();
        cng.ॱ();
    }

    private void ˋॱ() {
        this.ˋ.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).format(new Date())).append("\n\n");
        this.ʼ.execute(new Runnable(this) {
            final /* synthetic */ cmq ˋ;

            {
                this.ˋ = r1;
            }

            public void run() {
                try {
                    Thread.sleep(20000);
                } catch (InterruptedException e) {
                    cmp.ˊ.ˋ("Diagnoser", "timeout monitor interrupted, all tasks finished ahead of limit");
                }
                cmp.ˊ.ˋ("Diagnoser", ((6 - this.ˋ.ˎ) - this.ˋ.ˊ) + " task(s) timeout, terminate diagnose.");
                ((ThreadPoolExecutor) this.ˋ.ʼ).shutdownNow();
            }
        });
    }

    public Executor ॱ() {
        return this.ʼ;
    }

    public Context ˎ() {
        return this.ˏ;
    }

    public synchronized void ˊ(int i, int i2, String str) {
        Message obtainMessage = this.ॱॱ.obtainMessage();
        obtainMessage.what = i;
        obtainMessage.arg1 = i2;
        this.ॱॱ.sendMessage(obtainMessage);
        this.ˋ.append(str).append("\n");
        if (i2 == 2) {
            this.ˎ++;
        } else {
            this.ˊ++;
        }
        cmp.ˊ.ˋ("Diagnoser", "success task amount:" + this.ˎ + ", fail task amount:" + this.ˊ + ", current reporting:taskName=" + i + ", resultCode=" + i2);
        if (this.ˎ + this.ˊ == 6) {
            cmp.ˊ.ˋ("Diagnoser", "all task finished.");
            ((ThreadPoolExecutor) this.ʼ).shutdownNow();
            cnr.ˎ(this.ˋ.toString(), ॱ);
            obtainMessage = this.ॱॱ.obtainMessage();
            obtainMessage.what = 100;
            if (this.ˊ == 6) {
                obtainMessage.arg1 = -100;
            }
            this.ॱॱ.sendMessage(obtainMessage);
        }
    }

    private void ॱˊ() {
        File file = new File(ॱ);
        if (file.exists() && !file.delete()) {
            cmp.ˊ.ˏ("Diagnoser", "old file exist, but delete failed, will try again when log-to-file");
        }
    }

    public void ˋ() {
        ˏ();
        ॱॱ();
        ᐝ();
        ʼ();
        ʽ();
        ʻ();
    }

    public void ˊ() {
        ((ThreadPoolExecutor) this.ʼ).shutdownNow();
    }

    public void ˏ() {
        this.ʼ.execute(new cna(this));
    }

    public void ॱॱ() {
    }

    public void ᐝ() {
        this.ʼ.execute(new cnb(this));
    }

    public void ʼ() {
        this.ʼ.execute(new cmt(this));
    }

    public void ʽ() {
    }

    public void ʻ() {
        this.ʼ.execute(new cmw(this));
    }
}
